from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://51job.com/')
# driver.get('https://login.51job.com/login.php')
# driver.maximize_window()
driver.find_element(By.XPATH,'/html/body/div[1]/div[1]/div/div[3]/p/a[1]').click()
driver.find_element(By.XPATH,'//*[@id="NormalLoginBtn"]/span[3]/a').click()
driver.find_element(By.ID,'loginname').send_keys('18775994767')
driver.find_element(By.ID,'password').send_keys('Q111111.')
sleep(2)
driver.find_element(By.ID,'isread_em').click()
driver.find_element(By.ID,'login_btn_withPwd').click()
WebDriverWait(driver,15).until(expected_conditions.visibility_of_element_located((By.XPATH,'//*[@id="topIndex"]/div/p/a[1]')),'找不到元素')
# WebDriverWait 引包   expected_conditions 引包
driver.find_element(By.XPATH,'//*[@id="topIndex"]/div/p/a[1]').click()
driver.find_element(By.ID,'kwdselectid').send_keys('软件测试')
driver.find_element(By.XPATH,'/html/body/div[3]/div/div[1]/div/button').click()
sleep(3)
driver.find_element(By.XPATH,'/html/body/div[2]/div[3]/div/div[1]/div[1]/span[1]/em').click()

# print(driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div[2]/div[4]/div[1]/div[1]/div[2]/a').get_attribute(
#     "innerHTML"))
# companyxpath = html/body/div[2]/div[3]/div/div[2]/div[4]/div[1]/div[{i}]/div[2]/a
# title = companyxpath

# title = (driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div[2]/div[4]/div[1]/div[i]/div[2]/a').get_attribute(
#     "innerHTML"))

companyname = []
# for i in range(1,51):
#     # companyname.append(f'/html/body/div[2]/div[3]/div/div[2]/div[4]/div[1]/div[{i}]/div[2]/a')
#     companyname.append(driver.find_element(By.XPATH,f'/html/body/div[2]/div[3]/div/div[2]/div[4]/div[1]/div[{i}]/div[2]/a').get_attribute(
#     "innerHTML"))
# print(companyname)
    # / html / body / div[2] / div[3] / div / div[2] / div[4] / div[1] / div[2] / div[2] / a

for i in range(1,51):
    title = driver.find_element(By.XPATH,f'/html/body/div[2]/div[3]/div/div[2]/div[4]/div[1]/div[i]/div[2]/a').text

print(title)